Repository navigation
Conversation
quote_char: nil and strip: " " removed each padding character with delete_prefix!, which copies the rest of the string. A 400_000-character pad took about a second.
delete_prefix! in a loop copied the remainder for every leading character. A single regexp removes both ends. Fixes ruby#396
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #396.
strip: " "withquote_char: nilremoved the padding one character at a time. Eachdelete_prefix!copied the rest of the line, so a long run of the same character grew with the square of its length. On this machine, 400,000 leading spaces took about 1.1 seconds.strip: truewas already a singleString#strip!, and a quoted field was already stripped by a regexp inside the scanner. This path is the one that loops.The string strip is now one regexp anchored at both ends, built once when the parser is prepared. The same 400,000-character pad finishes in about 5 milliseconds, and the field value is unchanged.
The regression test parses short padded lines, including a multibyte strip character, and times
strip_valuedirectly. Timing the whole parse would be dominated by the one-byte reads used whenCSV_PARSER_SCANNER_TESTis set. The old loop takes about a second at this size, so the 0.25 second bound fails if the loop comes back.